<template>
  <el-dialog
    append-to-body
    :title="info"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    align="left"
    v-loading="currLoading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    width="700px">
    <div style="margin-top: 10px;">
      <product-item :curr-product="{
              id:product.productId,
              price:product.productPrice,
              model:product.productModel,
              nums:product.productNums,
              name:product.productName,
              image:product.productImage,
            }" v-for="(product,index) in productList" :key="index"/>
    </div>
    <el-form style="margin-top: 10px;" v-if="dialogVisible" ref="form" :model="form" label-width="150px" :rules="rules">
      <el-form-item label="商品打包数量:" align="left" prop="goodsCount">
        <el-input-number v-model="form.goodsCount"/>
      </el-form-item>
      <el-form-item label="商品总重量:" align="left" prop="goodsWeight">
        <el-input v-model.number="form.goodsWeight" style="width: 100px"></el-input>
        kg
      </el-form-item>
<!--      <el-form-item  v-if="sendData.time>0" label="配送信息:" align="left">-->
<!--        <el-tag type="success" v-text="'配送时间: '+sendData.time+'分钟'"></el-tag>-->
<!--        <el-tag type="success" v-text="'配送费用: '+ToMoney((sendData.money*0.01).toFixed(2)-0)"></el-tag>-->
<!--        <el-tag type="success" v-text="'配送距离: '+((sendData.distance*0.001).toFixed(2))+'km'"></el-tag>-->
<!--      </el-form-item>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
<!--      <el-button type="success" @click="getSendData">计算配送信息</el-button>-->
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
    <div style="background: #e3b6b6; border: 1px solid #a22d2d; color: #000000; line-height: 25px; text-indent: 5px;">
      注意: 起送地址为店铺地址
    </div>
  </el-dialog>
</template>

<script>
import AddressItem from '../Common/AddressItem'
import ProductItem from '../Common/ProductItem'

export default {
  name: 'OrderSubmitExpressSameCityDialog',
  components: {ProductItem, AddressItem},
  props: {
    successFunction: Function
  },
  data: function () {
    return {
      info: '订单确认发货(同城配送)',
      address: {},
      dialogVisible: false,
      currLoading: false,
      expressCompanyArr: dict.ExpressCompanyList,
      form: {
        id: 0,
        goodsCount: 1,
        goodsWeight: 1
      },
      rules: {
        goodsCount: [
          {required: true, message: '请输入 商品数量', trigger: ['blur', 'change']},
        ],
        goodsWeight: [
          {required: true, message: '请输入 商品重量', trigger: ['blur', 'change']},
        ]
      },
      orderDetail: {},
      productList: [],
      sendData: {
        money: 0,
        time: 0,
        distance: 0,
      }
    }
  },
  mounted () {
  },
  methods: {
    // 获取配送信息
    getSendData: function () {
      var $this = this
      $this.MyRequest($this.ApiDoNameSupplier + 'Order/getSameSendData', {
        id: $this.orderDetail.id,
        goodsCount: $this.form.goodsCount,
        goodsWeight: $this.form.goodsWeight
      }, function (sendData) {
        $this.sendData = sendData
        $this.$forceUpdate()
      }, function (msg) {
        $this.$message.error(msg)
      })
    },
    open: function (order, productList) {
      this.orderDetail = order
      this.productList = productList
      this.dialogVisible = true
    },
    submit: function () {
      let $this = this
      $this.$refs.form.validate((valid) => {
        if (valid) {
          var form = {
            id: $this.orderDetail.id,
            goodsWeight: $this.form.goodsWeight,
            goodsCount: $this.form.goodsCount,
          }
          $this.currLoading = true
          $this.MyRequest(this.ApiDoNameSupplier + 'SupplierOrder/sendSameCity', form, function () {
            $this.$message.success('操作成功')
            $this.currLoading = false
            $this.dialogVisible = false
            $this.$props.successFunction()
            $this.$forceUpdate()
          }, function () {
            $this.$message.success('操作失败，请重试')
            $this.currLoading = false
            $this.$forceUpdate()
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
